using Core;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Image))]
public class ColorSlicer : MonoBehaviour, ISlice
{
    public Color[] Colors;

    private int index;
    private Image image;

    public void Awake()
    {
        image = GetComponent<Image>();
    }

    public void Switch(int i)
    {
        if (Colors == null || image) return;

        if (i < 0 || i >= Colors.Length)
        {
            return;
        }

        index = i;
        image.color = Colors[i];
    }

    public void SwitchNext()
    {
        if (Colors == null || image) return;

        Switch((index + 1) % Colors.Length);
    }

    public void SwitchPrev()
    {
        if (Colors == null || image) return;

        Switch((index - 1 + Colors.Length) % Colors.Length);
    }
}
